package com.example.appforphysician.adapter;

import java.util.ArrayList;
import java.util.HashMap;

public class ServiceConnector {
	public static class PhysicianInfo {
		public String name;
		public String phone;
		public String address;
		public String specialist;
		public String hospital;
		public String hotline;
	}

	public static class PatientInfo {
		// ===
		public String name;
		public Integer age;
		public String birthday;

		// ===
		public String address;
		public String area;
		public String phone;

		// ===
		public String doctor;
		public String emergencyContact;
		
		// ===
		public String health;
		public String expired;
	}

	public static class MedicalHistory {
		public String physician;
		public String address;
		public String phone;

		// ===
		public Boolean q1Result;
		public String q1Explain;
		public Boolean q2Result;
		public String q2Explain;
		public Boolean q3Result;
		public String q31Explain;
		public Boolean q4Result;
		public String q4Explain;

		// ===
		public Boolean heartDisease;
		public Boolean highBloodPressure;
		public Boolean bloodDisease;
		public Boolean RheumaticFever;
		public Boolean diabetes;
		public Boolean stroke;
		public Boolean epilepsy;
		public Boolean arthritis;
		public Boolean tumorHistory;
		public Boolean VD;
		public Boolean nervousDisorders;
		public Boolean radiationTreatment;
		public Boolean liverDisease;
		public Boolean kidneyDisease;
		public Boolean hepatitis;
		public Boolean asthma;
		public Boolean tuberculosis;
		public Boolean AIDSorHIV;
	}

	public static class AuthInfo {
		public String username;
		public String password;
	}

	public static class ScheduleItem {
		public String patientId;
		public String name;
		public String date;
		public String time;
		public String service;
		public String address;
	}

	public static class PhysicianSchedule {
		private ArrayList<ScheduleItem> list;

		public PhysicianSchedule() {
			list = new ArrayList<ServiceConnector.ScheduleItem>();
			ScheduleItem si;

			si = new ScheduleItem();
			si.patientId = "P01";
			si.name = "Trần Hồng Nghi";
			si.date = "7/1/2014";
			si.time = "8:30 AM";
			si.service = "Chăm sóc người già";
			si.address = "Tân Hưng, Phú Nhuận, Tp.HCM";
			list.add(si);

			si = new ScheduleItem();
			si.patientId = "P02";
			si.name = "Phạm Thanh Quốc";
			si.date = "8/1/2014";
			si.time = "7:30 AM";
			si.service = "Khám tổng quát";
			si.address = "Phường 7, Q.10, Tp.HCM";
			list.add(si);

			si = new ScheduleItem();
			si.patientId = "P03";
			si.name = "Trần Văn Tiến";
			si.date = "9/1/2014";
			si.time = "12:30 PM";
			si.service = "Lấy mẫu máu";
			si.address = "Bình Chánh, Tp.HCM";
			list.add(si);

			si = new ScheduleItem();
			si.patientId = "P04";
			si.name = "Lê Thị Nghĩa";
			si.date = "10/1/2014";
			si.time = "1:30 PM";
			si.service = "Đo nồng độ đường";
			si.address = "Phường 1, Q.7, Tp.HCM";
			list.add(si);

			si = new ScheduleItem();
			si.patientId = "P05";
			si.name = "Cao Văn Sơn";
			si.date = "15/1/2014";
			si.time = "8:30 AM";
			si.service = "Đo tim mạch";
			si.address = "Q.7, Tp.HCM";
			list.add(si);
		}

		public ArrayList<HashMap<String, String>> printAdapter() {
			ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
			for (ScheduleItem si : list) {
				HashMap<String, String> map = new HashMap<String, String>();
				map.put("PatientID", si.patientId);
				map.put("PatientName", si.name);
				map.put("PatientDate", si.date);
				map.put("PatientTime", si.time);
				map.put("PatientService", si.service);
				map.put("PatientAddress", si.address);
				mylist.add(map);
			}
			return mylist;
		}

		public void addSchedule(String name, String service, String address,
				String date, String time) {
			
			ScheduleItem si;

			si = new ScheduleItem();
			si.patientId = "P0" + list.size();
			si.name = name;
			si.date = date;
			si.time = time;
			si.service = service;
			si.address = address;
			list.add(si);
		}
	}

	// =======================================================
	private static ServiceConnector singleton = null;

	public static ServiceConnector getSingleton() {
		if (singleton == null)
			singleton = new ServiceConnector();

		return singleton;
	}

	private ServiceAdapter adapter = null;
	private AuthInfo currentUser = null;
	private PhysicianSchedule physicianSchedule = null;

	// =======================================================
	private ServiceConnector() {
		adapter = new ServiceAdapter();
	}

	public Boolean doLogin(String username, String password) {
		if (adapter.authenticate(username, password)) {
			currentUser = new AuthInfo();
			currentUser.username = username;
			currentUser.password = password;
			
			return true;
		}

		return false;
	}

	public AuthInfo getAuthInfo() {
		return currentUser;
	}

	public PhysicianInfo getPhysicianInfo() {
		PhysicianInfo result = new PhysicianInfo();

		result.name = "Nghi Trần";
		result.phone = "0919271171";
		result.address = "Nguyen Van Linh, Quan 7, Tp.HCM";
		result.specialist = "Khoa Vat ly tri lieu";
		result.hospital = "Benh vien Quan 7";
		result.hotline = "082712783";

		return result;
	}

	public PhysicianSchedule getPhysicianSchedule() {
		if (physicianSchedule == null)
			physicianSchedule = new PhysicianSchedule();

		return physicianSchedule;
	}

	// ==========================================================
	public PatientInfo getPatientInfo() {
		PatientInfo result = new PatientInfo();

		result.name = "Phạm Thanh Quốc";
		result.age = 18;
		result.birthday = "26/12/1986";
		result.address = "Đa Khoa Củ Chi";
		result.area = "Tp HCM";
		result.phone = "0908226445";
		result.emergencyContact = "0908226445";
		result.doctor = "Trần Hồng Nghi";
		result.health = "GOOD";
		result.expired = "8/2014";

		return result;
	}

	public MedicalHistory getPatientHistory() {
		MedicalHistory result = new MedicalHistory();

		result.physician = "Trần Hồng Nghi";
		result.address = "Đa Khoa Củ Chi";
		result.phone = "0908456259";

		result.q1Result = true;
		result.q1Explain = "High blood presser";
		result.q2Result = false;
		result.q2Explain = "No";
		result.q3Result = true;
		result.q31Explain = "One or two cigarette package per day";
		result.q4Result = false;
		result.q4Explain = "Nothing";

		result.heartDisease = false;
		result.highBloodPressure = true;
		result.bloodDisease = false;
		result.RheumaticFever = false;
		result.diabetes = false;
		result.stroke = true;
		result.epilepsy = false;
		result.arthritis = false;
		result.tumorHistory = true;
		result.VD = false;
		result.nervousDisorders = true;
		result.radiationTreatment = false;
		result.liverDisease = false;
		result.kidneyDisease = false;
		result.hepatitis = true;
		result.asthma = false;
		result.tuberculosis = false;
		result.AIDSorHIV = false;

		return result;
	}
}
